/**
 * JAVACC DEMO 1.0
 * @copy right iussoft company All rights reserved.
 * @Package com.iussoft.portal.servlet
 */
package com.apache.portal.contorller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.apache.passport.common.PassportHelper;
import com.apache.tools.StrUtil;
import com.apache.uct.common.LoginUser;
import com.apache.uct.common.PBOSSOTools;

/**
 * description:  
 */
public abstract class BaseAction extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		setLoginUser(request);
		doInvoke(request, response);
	}

	protected abstract void doInvoke(HttpServletRequest request, HttpServletResponse response) throws ServletException,
			IOException;

	/**
	 * description:  获取当前登录用户信息
	 */
	protected void setLoginUser(HttpServletRequest request) {
		if (null == request.getSession().getAttribute("loginUser")) {
			String cookieValue = PassportHelper.getInstance().getCurrCookie(request);
			if (StrUtil.isNull(cookieValue)) {
				request.getSession().removeAttribute("loginUser");
			} else {
				try {
					String value = PassportHelper.getInstance().getCurrCookie(request, "_uc.sso");
					if (StrUtil.isNotNull(value)) {
						//value = DesUtils.getInstance().decrypt(value);
						LoginUser loginUser = PBOSSOTools.getLoginUserFromUserCenterSso(cookieValue);
						if (null != loginUser)
							request.getSession().setAttribute("loginUser", loginUser);
					}
				} catch (Exception e) {
				}
			}
		}
	}
}
